package com.contextor.magiccards.web.to.user;

import com.contextor.magiccards.model.cards.MagicSchool;
import com.contextor.magiccards.model.character.Personage;
import com.contextor.magiccards.model.user.User;
import com.contextor.magiccards.web.to.BaseTO;

/**
 * User: Sergey
 * Date: 05.04.2011 21:29:42
 */
public class PersonageTO extends BaseTO {
    public String name;
    public Integer level;
    public String magicSchool;

    public PersonageTO() {
    }

    public PersonageTO(Personage personage, String uid) {
        this.id = personage.getId();
        this.userId = uid;
        this.name = personage.getName();
        this.level = personage.getLevel();
        this.magicSchool = personage.getMagicSchool().name();
    }

    public Personage toModel() {
        final Personage personage = new Personage();
        personage.setId(this.id);
        personage.setUser(new User(this.userId));
        personage.setName(this.name);
        personage.setLevel(this.level);
        personage.setMagicSchool(MagicSchool.valueOf(this.magicSchool));
        return personage;
    }
}
